<template>
	<view>
		<cu-custom bgColor="bg-gradual-fff" isBack="true">
			<block slot="content">会员权益</block> 
		</cu-custom>
		<loading-view v-show="showLoading"></loading-view>
		<view v-show="!showLoading">
			<view class="viewbox"></view>
			<view class="user_vip_a" v-if="user_info.level.level_id==0" :style="'background-image:url('+user_wvip_bj+');'">
				<view class="user_vip_a_a">
					<view class="user_vip_a_a_a" @click="goPage('/pages/notice/info?type=2')">会员规则</view>
					<view class="user_vip_a_a_b">
						<u-icon name="arrow-right" color="#fff" size="10"></u-icon>
					</view>
				</view>
				<view class="user_vip_a_b">
					<view class="user_vip_a_b_a">
						<custom-image :lazy-load="true" width="100rpx" height="100rpx" radius="50%" lazy-load :src="user_info.avatar"></custom-image>
					</view>
					<view class="user_vip_a_b_b">
						<view class="user_vip_a_b_b_a">{{user_info.username?user_info.username:user_info.nickname}}</view>
						<view class="user_vip_a_b_b_b">畅学海量精品课程 下单享优惠</view>
					</view>
					<view class="user_vip_a_b_c" @click="goPage('/pages/user/user_vip_log')">购买记录</view>
				</view>
			</view>
			<view class="user_vip_a" v-if="user_info.level.level_id>0" :style="'background-image:url('+user_yvip_bj+');'">
				<view class="user_vip_a_c" :style="'background-image:url('+user_info.level.level_img+');'">{{user_info.level.level_name}}</view>
				<view class="user_vip_a_a">
					<view class="user_vip_a_a_a" @click="goPage('/pages/notice/info?type=2')">会员规则</view>
					<view class="user_vip_a_a_b">
						<u-icon name="arrow-right" color="#fff" size="10"></u-icon>
					</view>
				</view>
				<view class="user_vip_a_d">
					<view class="user_vip_a_d_a">
						<custom-image :lazy-load="true" width="120rpx" height="120rpx" radius="50%" lazy-load :src="user_info.avatar"></custom-image>
					</view>
					<view class="user_vip_a_d_b">
						<view class="user_vip_a_d_b_a">{{user_info.username?user_info.username:user_info.nickname}}</view>
						<view class="user_vip_a_d_b_b">有效期至：{{user_info.vip_time}}</view>
						<view class="user_vip_a_d_b_c">
							<u-line-progress height="6" :percentage="60" activeColor="#FFFFFF" inactiveColor="#A69BE3"></u-line-progress>
						</view>
					</view>
				</view>
				<view class="user_vip_a_e">
					<view class="user_vip_a_e_a">*续费会员将在当前会员到期后生效</view>
					<view class="user_vip_a_e_b" @click="goPage('/pages/user/user_vip_log')">购买记录</view>
				</view>
			</view>
			<view class="user_vip_b">
				<view class="user_vip_b_a">选择开卡套餐</view>
				<view class="user_vip_b_b">
					<view class="l_bg" @click="user_vip_click(item)" v-for="(item, index) in user_vip_list">
						<view class="bor_jb">
							<view class="l_cen">
								<view class="l_top">
									<view class="l_bottom">
										<view class="user_vip_b_b_a">
											<view class="user_vip_b_b_a_a">
												<custom-image :lazy-load="true" width="99rpx" height="99rpx" radius="0" lazy-load :src="item.image"></custom-image>
											</view>
											<view class="user_vip_b_b_a_b">{{item.name}}</view>
											<view class="user_vip_b_b_a_c" :style="'background-image:url('+(level_id==item.id?user_vip_yicon:user_vip_wicon)+');'">
												优惠￥{{item.discount_price}}
											</view>
											<view class="user_vip_b_b_a_d">
												<price-format :price="item.money" subscriptSize="20" firstSize="48"></price-format>
												<span>/{{item.num}}天</span>
											</view>
											<view class="user_vip_b_b_a_e">￥{{item.original_price}}</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="user_vip_b_a" style="margin-top: 50rpx;">会员权益</view>
				<view class="user_vip_b_c">
					<view class="user_vip_b_c_a" v-for="(item, index) in level_privilege">
						<view class="user_vip_b_c_a_a">
							<custom-image :lazy-load="true" width="57rpx" height="57rpx" radius="0" lazy-load :src="item.image"></custom-image>
						</view>
						<view class="user_vip_b_c_a_b">
							<view class="user_vip_b_c_a_b_a">{{item.name}}</view>
							<view class="user_vip_b_c_a_b_b">{{item.remark}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="user_vip_c">
				<view class="user_vip_c_a">
					<span>¥</span>{{money}}
				</view>
				<view class="user_vip_c_b" @click="user_pay_click()">确认提交</view>
			</view>
		</view>
	</view>
</template>
<script>
import request from '@/common/request.js';	
export default {
	data() {
		return {
			showLoading:true,
			user_wvip_bj:request.baseUrl_img+'/img/user_wvip_bj.png',
			user_yvip_bj:request.baseUrl_img+'/img/user_wvip_bj.png',
			user_vip_wicon:request.baseUrl_img+'/img/user_vip_wicon.png',
			user_vip_yicon:request.baseUrl_img+'/img/user_vip_yicon.png',
			description:'',
			uid:0,
			user_vip_list:[],
			user_info:[],
			level_id:0,
			level_privilege:[],
			money:'0.00'
		}
	},
	onShow(){
		this.uid=uni.getStorageSync('uid');
	},
	created() {
	  uni.$on("refreshorder", () => {
	    this.user_click();
	  });
	},
	destroyed: function () {
	  uni.$off("refreshorder");
	},
	mounted() {
		this.home_config_post();
		this.user_click();
	},
	methods: {
		user_vip_click(item){
			this.level_privilege=item.level_privilege;
			this.level_id=item.id;
			this.money=item.money;
		},
		user_pay_click(){
			let paramsList = {
				uid:this.uid,
				level:this.level_id
			}
			let optsList = {
				url: 'ul-buy',
				method: 'post'
			};
			uni.showLoading({
				title: '提交中...',
				mask: true
			})
			let _this=this;
			request.httpTokenRequest(optsList, paramsList).then(res => {
				if(res.data.code == 200){
					uni.navigateTo({
						url: '/pages/confirm_order/order_details?order_sn='+res.data.data.order_sn+'&from=vip'
					})
				}else{
					uni.showToast({
						title: res.data.msg,
						icon:'none',
						duration: 2000
					});
				}
			});
		},
		prepay_click(order_sn,type){
			let paramsList = {
				uid:this.uid,
				order_sn:order_sn,
				type:type
			}
			let optsList = {
				url: 'p-prepay',
				method: 'post'
			};
			uni.showLoading({
				title: '调取支付中',
				mask: true
			})
			let _this=this;
			request.httpTokenRequest(optsList, paramsList).then(res => {
				uni.hideLoading();
				if(res.data.code == 200){
					uni.requestPayment({
						provider: 'wxpay',
						timeStamp: String(res.data.data.timeStamp),
						nonceStr: res.data.data.nonceStr,
						package: res.data.data.package,
						signType: res.data.data.signType,
						paySign: res.data.data.paySign,
						success: function (res) {
							_this.user_click();
						},
						fail: function (err) {
							console.log(err);
							uni.showToast({
								title:'支付已取消',
								icon:'none',
								duration: 2000
							});
						}
					});
				}else{
					uni.showToast({
						title: res.data.msg,
						icon:'none',
						duration: 2000
					});
				}
			});
		},
		user_click(){
			let paramsList = {
				'uid':this.uid
			}
			let optsList = {
				url: 'u-role_config',
				method: 'post'
			};
			let _this=this;
			request.httpTokenRequest(optsList, paramsList).then(res => {
				uni.hideLoading();
				if(res.data.code == 200){
					_this.user_info=res.data.data;
				}
			});
		},
		home_config_post(){
			let paramsList = {
				
			}
			let optsList = {
				url: 'ul-lists',
				method: 'post'
			};
			let _this=this;
			request.httpRequest(optsList, paramsList).then(res => {
				if(res.data.code == 200){
					_this.user_vip_list=res.data.data;
					_this.level_privilege=_this.user_vip_list[0].level_privilege;
					_this.level_id=_this.user_vip_list[0].id;
					_this.money=_this.user_vip_list[0].money;
				}
				_this.showLoading=false;
			});
		},
		goPage(url) {
			if (!this.$util.isLogin()) {
				return;
			}
			uni.navigateTo({
				url
			});
		},
	}
}
</script>

<style  lang="scss" scoped>
	.user_vip_a{
		width: 710rpx;
		height: 360rpx;
		margin: auto;
		margin-top: 40rpx;
		background-position: center;
		background-repeat: no-repeat;
		background-size: 710rpx 360rpx;
		position: relative;
	}
	.user_vip_a_a{
		position: absolute;
		width: 156rpx;
		height: 40rpx;
		background: rgba(255,255,255,0.01);
		border-radius: 20rpx;
		border: 1px solid #FFFFFF;
		top:55rpx;
		right: 47rpx;
	}
	.user_vip_a_a_a{
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #FFFFFF;
		line-height: 35rpx;
		float: left;
		text-align: center;
		margin-left: 20rpx;
	}
	.user_vip_a_a_b{
		float: left;
		margin-top: 5rpx;
	}
	.user_vip_a_b{
		width: 660rpx;
		height: 140rpx;
		background: #2E1D4B;
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		position: absolute;
		bottom: 0;
		left: 25rpx;
		padding: 20rpx 30rpx;
	}
	.user_vip_a_b_a{
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		float: left;
	}
	.user_vip_a_b_b{
		float: left;
		margin-left: 25rpx;
		margin-top: 17rpx;
	}
	.user_vip_a_b_b_a{
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 36rpx;
	}
	.user_vip_a_b_b_b{
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #FFFFFF;
		line-height: 36rpx;
	}
	.user_vip_a_b_c{
		float: right;
		width: 160rpx;
		height: 50rpx;
		background: #734FB5;
		border-radius: 25rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		font-size: 24rpx;
		color: #FFFFFF;
		line-height: 50rpx;
		text-align: center;
		margin-top: 30rpx;
	}
	.user_vip_a_c{
		position: absolute;
		top:30rpx;
		left: 30rpx;
		width:auto;
		height: 40rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 22rpx;
		color:#fff;
		background-repeat: no-repeat;
		background-position: left;
		background-size: 36rpx;
		padding-left: 40rpx;
	}
	.user_vip_a_d{
		margin-top: 100rpx;
		overflow: hidden;
		display: inline-block;
	}
	.user_vip_a_d_a{
		width: 120rpx;
		height: 120rpx;
		float: left;
		border-radius: 50%;
		margin-left: 40rpx;
	}
	.user_vip_a_d_b{
		float: left;
		margin-left: 25rpx;
		overflow: hidden;
		width: 500rpx;
	}
	.user_vip_a_d_b_a{
		font-family: PingFang SC;
		font-weight: 800;
		font-size: 36rpx;
		color: #FFFFFF;
		line-height: 70rpx;
	}
	.user_vip_a_d_b_b{
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 36rpx;
	}
	.user_vip_a_d_b_c{
		width: 250rpx;
		margin-top: 20rpx;
	}
	.user_vip_a_e{
		height: 70rpx;
		overflow: hidden;
		padding:0 40rpx;
		margin-top: 20rpx;
	}
	.user_vip_a_e_a{
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #FFFFFF;
		line-height: 70rpx;
		float: left;
	}
	.user_vip_a_e_b{
		width: 160rpx;
		height: 70rpx;
		background: #FFFFFF;
		border-radius: 35rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		font-size: 24rpx;
		color: #734FB5;
		line-height: 70rpx;
		text-align: center;
		float: right;
	}
	.user_vip_b{
		width: 750rpx;
		box-shadow: inset 0 0 20rpx 20rpx rgba(85, 56, 105, 0.6);
		margin-top: 30rpx;
		border-radius: 20rpx;
		padding: 45rpx 0;
		padding-bottom: 170rpx;
	}
	
	.user_vip_b_a{
		width: 710rpx;
		margin: auto;
		font-family: PingFang SC;
		font-weight: 800;
		font-size: 30rpx;
		color: #F7F7F9;
		line-height: 22rpx;
	}
	.user_vip_b_b{
		margin-left: 25rpx;
		overflow: hidden;
		position: relative;
		margin-top: 30rpx;
	}
	.l_bg{
		float: left;
		width: 218rpx;
		margin-right: 25rpx;
	}
	.user_vip_b_b_a{
		width: 100%;
		overflow: hidden;
		padding-bottom: 40rpx;
	}
	.user_vip_b_b_a_a{
		width: 90rpx;
		height: 90rpx;
		margin: auto;
		margin-top: 20rpx;
	}
	.user_vip_b_b_a_b{
		font-family: PingFang SC;
		font-weight: 800;
		font-size: 24rpx;
		color: #F7F7F9;
		line-height: 48rpx;
		text-align: center;
		margin-top: 10rpx;
	}
	.user_vip_b_b_a_c{
		width: 168rpx;
		height: 53rpx;
		margin: auto;
		margin-top: 10rpx;
		background-position: center;
		background-repeat: no-repeat;
		background-size: 168rpx 53rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 18rpx;
		color: #F7F7F9;
		line-height: 36rpx;
		text-align: center;
	}
	.user_vip_b_b_a_d{
		font-family: PingFang SC;
		font-weight: 800;
		font-size:48rpx;
		color: #D5BEFF;
		line-height: 36rpx;
		text-align: center;
		margin-top: 30rpx;
	}
	.user_vip_b_b_a_d span{
		font-size:20rpx;
	}
	.user_vip_b_b_a_e{
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #6A4B7C;
		line-height: 36rpx;
		text-decoration-line: line-through;
		text-align: center;
		margin-top: 10rpx;
	}
	.user_vip_b_c{
		width: 710rpx;
		overflow:hidden;
		margin: auto;
	}
	.user_vip_b_c_a{
		margin-top: 45rpx;
		float: left;
		overflow:hidden;
	}
	.user_vip_b_c_a_a{
		float: left;
		width: 57rpx;
		height: 57rpx;
	}
	.user_vip_b_c_a_b{
		float:right;
		margin-left: 20rpx;
	}
	.user_vip_b_c_a_b_a{
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 35rpx;
	}
	.user_vip_b_c_a_b_b{
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #FFFFFF;
		line-height: 22rpx;
		margin-top: 10rpx;
	}
	.user_vip_b_c_a:nth-child(2n){
		float: right;
	}
	.user_vip_c{
		width: 750rpx;
		height: 130rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 1rpx 0rpx 0rpx #DDDDDD;
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		position: fixed;
		padding:0 30rpx;
		bottom: 0;
	}
	.user_vip_c_a{
		float: left;
		font-family: PingFang SC;
		font-weight: 800;
		font-size:48rpx;
		color: #FF6000;
		line-height: 130rpx;
	}
	.user_vip_c_a span{
		font-size:20rpx;
	}
	.user_vip_c_b{
		width: 360rpx;
		height: 88rpx;
		background: #734FB5;
		border-radius: 44rpx;
		float: right;
		font-family: PingFang SC;
		font-weight: 800;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		margin-top: 20rpx;
		
	}
</style>
